package com.util;

import java.io.UnsupportedEncodingException;

public class StringUtils {
	public static boolean isBlank(String string) {
		return string == null || string.equals("");
	}
	public static boolean isNotBlank(String string) {
		return !isBlank(string);
	}
	
	

	// 字符串转换unicode
	public static String stringToUnicode(String string) {
		StringBuffer unicode = new StringBuffer();
		for (int i = 0; i < string.length(); i++) {
			char c = string.charAt(i); // 取出每一个字符
			unicode.append("\\u" + Integer.toHexString(c));// 转换为unicode
		}
		return unicode.toString();
	}

	// unicode 转字符串
	public static String unicodeToString(String unicode) {
		StringBuffer string = new StringBuffer();
		String[] hex = unicode.split("\\\\u");
		for (int i = 1; i < hex.length; i++) {
			int data = Integer.parseInt(hex[i], 16);// 转换出每一个代码点
			string.append((char) data);// 追加成string
		}
		return string.toString();
	}

	public static void main(String[] args) {

		try {
			String str = new String("好|6".getBytes(), "utf-8");
			String _t = stringToUnicode(str);
			String gbk = unicodeToString(_t);
			System.out.println(gbk);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
}
